import {
  Entity,
  Column,
  ManyToOne,
  JoinColumn,
  OneToMany,
  ManyToMany,
  JoinTable,
} from "typeorm";
import BaseEntity from "./base";
import { User } from "./user";
import { Attachment } from "./attachment";
import { Board } from "./board";
import { Comment } from "./comment";
import { Tag } from "./tag";

@Entity("posts")
export class Post extends BaseEntity {
  @Column()
  title: string;

  @Column()
  content: string;

  @OneToMany(() => Attachment, (attachment) => attachment.post)
  attachments: Attachment[];

  @OneToMany(() => Comment, (comment) => comment.user)
  comments: Comment[];

  @ManyToOne(() => Board, (board) => board.posts)
  @JoinColumn()
  board: Board;

  @ManyToOne(() => User, (user) => user.posts)
  @JoinColumn()
  user: User;

  @ManyToMany(() => Tag, (tag) => tag.posts)
  @JoinTable()
  tags: Tag[];
}
